﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.OracleClient;
using System.Data;


public class UserDAL
{
    DataAccess db;
    public UserDAL()
    {
        db = new DataAccess();
    }


    public bool CheckLogin(User user)
    {
        OracleParameter[] listPara = new OracleParameter[3];

        listPara[0] = new OracleParameter("results", OracleType.Cursor);
        listPara[0].Direction = ParameterDirection.Output;


        listPara[1] = new OracleParameter("user", OracleType.NVarChar, 256);
        listPara[1].Direction = ParameterDirection.Input;
        listPara[1].Value = user.Username;

        listPara[2] = new OracleParameter("pass", OracleType.NVarChar, 256);
        listPara[2].Direction = ParameterDirection.Input;
        listPara[2].Value = user.Keyword;

        try
        {
            DataTable dt = new DataTable();
            dt = db.ExecuteSelect("proc_users.User_CheckLogined", listPara);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        catch (Exception)
        {
            return false;
        }
    }

    public DataTable Users()
    {
        OracleParameter[] listPara = new OracleParameter[1];

        listPara[0] = new OracleParameter("results", OracleType.Cursor);
        listPara[0].Direction = ParameterDirection.Output;

        try
        {
            DataTable dt = new DataTable();
            dt = db.ExecuteSelect("proc_users.User_SelectedAll", listPara);
            if (dt.Rows.Count > 0)
                return dt;
            return null;
        }
        catch (Exception)
        {
            return null;
        }
    }
}